package com.wlb365.admin.modules.monitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlb365.admin.modules.monitor.entity.MonitorInfo;
import com.wlb365.admin.modules.monitor.entity.MonitorInfoError;
import com.wlb365.admin.modules.monitor.service.MonitorInfoErrorService;
import com.wlb365.admin.modules.monitor.service.MonitorInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.wlb365.admin.common.support.controller.BaseController;
import com.wlb365.admin.common.dto.R;

import java.util.List;

/**
 * <p>
 * 接口监控信息 前端控制器
 * </p>
 *
 * @author
 * @since 2021-01-27 13:18:15
 */
@RestController
@RequestMapping("monitor/info")
public class MonitorInfoController extends BaseController {

    @Autowired
    private MonitorInfoService infoService;
    @Autowired
    private MonitorInfoErrorService monitorInfoErrorService;

    @RequiresPermissions("monitor:info:index")
    @GetMapping("index")
    public ModelAndView index() {
        return new ModelAndView("monitor/info");
    }

    @GetMapping(value = "list/data")
    public R listData(MonitorInfo info) {
        Page<MonitorInfo> page = infoService.listInfoPage(info);
        return R.ok(page);
    }

    @GetMapping("infoError")
    public ModelAndView infoError(String instanceId, String routeId) {
        ModelAndView mv = new ModelAndView("monitor/infoError.html");
        MonitorInfoError infoError = new MonitorInfoError();
        infoError.setInstanceId(instanceId);
        infoError.setRouteId(routeId);
        mv.addObject("editInfo", infoError);
        return mv;
    }

    @GetMapping(value = "infoError/list/data")
    public R infoErrorListData(MonitorInfoError infoError) {
        Page<MonitorInfoError> page = monitorInfoErrorService.listInfoErrorPage(infoError);
        return R.ok(page);
    }

    @RequiresPermissions("monitor:info:del")
    @PostMapping(value = "batchdel")
    public R batchdel(@RequestParam("ids") List
            <Long> ids) {
        infoService.removeByIds(ids);
        return R.ok();
    }

    @RequiresPermissions("monitor:info:del")
    @PostMapping(value = "del/{id}")
    public R del(@PathVariable Long id) {
        infoService.removeById(id);
        return R.ok();
    }

    @GetMapping(value = "get/{id}")
    public R get(@PathVariable Long id) {
        return R.ok(infoService.getById(id));
    }

}

